<?php
/************************************
*   新浪相册 7.0
*   @file:user_set_intro.php
*   @intro:
*   @author:shaopu@
*   @date:Mon Nov 24 16:17:16 CST 2008
************************************/


class member_apply extends api_controllor 
{
    private $_email;
    private $_name;
    private $_mobile;
    private $_company;
    private $_fax;
    private $_message;
    
    private $oSess;

    public function __construct($get_param)
    {
        $this->__need_login = false;
        parent::__construct($get_param);
    }
    
    public function run()
    {
        $this->check_para();
        
        $this->oSess->get('history' , $visit_history);
        $data = array(
            'name' => $this->_name,
            'fax' => $this->_fax,
            'email' => $this->_email,
            'mobile' => $this->_mobile,
            'message' => $this->_message,
            'company' => $this->_company,
            'visit_history' => $visit_history
        );
        
        $oMemberApply = K::load_mod('member_apply');
        $oMemberApply->create($data) or $this->err_output(K_SYSCODE_SYSTEM_BUSY);
        
        //语言
        if(in_array($_COOKIE[K_COOKIE_LANG] , array(K_LANG_CHN , K_LANG_ENG)))
        {
            $this->__isLangEng = $_COOKIE[K_COOKIE_LANG] == K_LANG_ENG ? true : false;
            $L = K::config($_COOKIE[K_COOKIE_LANG]);
        }
        else 
        {
            $this->__isLangEng = K_DEFAULT_LANG == K_LANG_ENG ? true : false;
            $L = K::config(K_DEFAULT_LANG);
        }
        
        echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ';
        echo '<script>alert("'.$L['pApplySuc'].'");</script>'.$L['redirect'];
        $this->redirect('/navi' , 1);
    }
    
    public function check_para()
    {
        //验证码
        $vcode = $this->input('vcode');
        $this->oSess = K::session();
        if(!$this->oSess->check_validate_code($vcode))
            $this->redirect('/apply/vcode');
        
        
        $this->_name = $this->input('name');
        $this->_company = $this->input('company');
        $this->_email = $this->input('email');
        $this->_mobile = $this->input('phone');
        $this->_fax = $this->input('fax');
        $this->_message = $this->input('message');
        
        
        
        if(!lib_validater::is_email($this->_email))
            $this->redirect('/apply/email');
        elseif(empty($this->_name))
            $this->redirect('/apply/uname');
            
        elseif($this->_mobile && !preg_match('/^[0-9_]{5,20}$/' , $this->_mobile))
            $this->redirect('/apply/mob');
        elseif($this->_fax && !is_numeric($this->_fax))
            $this->redirect('/apply/fax');
    }
}


?>